/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package py.com.sole.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author bala
 */
@Entity
@Table(name = "profesores")
@XmlRootElement
@NamedQueries({
  @NamedQuery(name = "Profesor.findAll", query = "SELECT p FROM Profesor p WHERE p.activo=TRUE"),
  @NamedQuery(name = "Profesor.findById", query = "SELECT p FROM Profesor p WHERE p.id = :id and p.activo=TRUE"),
  @NamedQuery(name = "Profesor.findProfesorPersona", query = "SELECT p.id, per.nombre, per.apellido, per.telefono, per.email FROM Profesor p LEFT JOIN p.persona per WHERE p.activo=TRUE")})
public class Profesor implements Serializable {

  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Basic(optional = false)
  @Column(nullable = false)
  private Integer id;
  @JoinTable(name = "profesores_materias", joinColumns = {
    @JoinColumn(name = "profesores", referencedColumnName = "id", nullable = false)}, inverseJoinColumns = {
    @JoinColumn(name = "materias", referencedColumnName = "id", nullable = false)})
  @ManyToMany
  private List<Materia> materiaList;

  @JoinColumn(name = "persona", referencedColumnName = "id", nullable = false)
  @ManyToOne(optional = false)
  private Persona persona;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "profesore")
  private List<Clase> claseList;
  private Boolean activo;

  public Profesor() {
  }

  public Profesor(Integer id) {
    this.id = id;
  }

  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

  @XmlTransient
  public List<Materia> getMateriaList() {
    return materiaList;
  }

  public void setMateriaList(List<Materia> materiaList) {
    this.materiaList = materiaList;
  }

  /*@XmlTransient
   public Set<Materia> getMateriaList() {
   return materiaList;
   }

   public void setMateriaList(Set<Materia> listMateria) {
   this.materiaList = listMateria;
   }*/
  public Persona getPersona() {
    return persona;
  }

  public void setPersona(Persona persona) {
    this.persona = persona;
  }

  public Boolean isActivo() {
    return activo;
  }

  public void setActivo(Boolean activo) {
    this.activo = activo;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (id != null ? id.hashCode() : 0);
    return hash;
  }

//	@XmlTransient
//	public List<Clase> getClaseList() {
//		return claseList;
//	}
//
//	public void setClaseList(List<Clase> claseList) {
//		this.claseList = claseList;
//	}
  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof Profesor)) {
      return false;
    }
    Profesor other = (Profesor) object;
    if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "py.com.sole.model.Profesor[ id=" + id + " ]";
  }
}
